// pages/mine/face/face.js
var gd = getApp().globalData;
const net = require('../../../utils/net.js');
var posting = false;
var dialog = null;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    faceurl:"",
    facewidth:"0",
    hidetip: wx.getStorageSync("face1_status")==2
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(gd);
    var sysinfo = gd.sysinfo;
    var w = sysinfo.windowWidth;
    console.log(sysinfo);
    this.setData({
      facewidth: (w - 100) * 0.8
    })
  },
  error(e){
    console.log(e);
  },
  getface(){
    var that = this;
    // if (that.data.hidetip){
    //     dialog.showDialog({
    //       msg: "已通过，无需再次采集"
    //     });
    //   return;
    // }
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['compressed'], 
      sourceType: ['camera'], 
      success: function (res) {
        var tempFilePaths = res.tempFilePaths
        wx.showLoading({
          title: '上传中...',
        })
        net.uploadFile({
          url: '/Member3DImage', //仅为示例，非真实的接口地址
          filePath: tempFilePaths[0],
          name: 'file',
          formData: {
              member_id:gd.id ,
              shop_id:gd.shop_id
          },
          success: function (res) {
            var data = res.data
            if(typeof data !=Object){
              data = JSON.parse(data);
            }
            if(data.flag){
              that.setData({
                hidetip:true,
                faceurl: data.data
              })
              gd.face1 = data.data;
              gd.face1_status = 2;
              wx.setStorageSync("face1", data.data)
              wx.setStorageSync("face1_status",2)
              dialog.showDialog({
                msg:data.msg
              })
              setTimeout(function(){
                wx.navigateBack({})
              },1000);
            }else{
              if(data.data!=0){
                that.setData({
                  faceurl:data.data
                })
                wx.setStorageSync("face1", data.data)
                gd.face1 = data.data;
                wx.setStorageSync("face1_status",1)
                gd.face1_status = 1;
              }else{
                wx.setStorageSync("face1_status", 0)
                gd.face1_status = 0;
              }
              dialog.showDialog({
                msg: data.msg
              })
            }
          },fail(res){
            console.log(res);
            dialog.showDialog({
              msg: "服务器异常"
            })
          },complete(){
            wx.hideLoading();
            console.log(gd);
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    dialog = this.selectComponent("#dialog");
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})